package com.jiangjiang.eshop.membership.biz;

import com.jiangjiang.eshop.membership.convert.UserDetailConvert;
import com.jiangjiang.eshop.membership.domain.UserDetailEntity;
import com.jiangjiang.eshop.membership.dto.UserAccountDTO;
import com.jiangjiang.eshop.membership.dto.UserDetailDTO;
import com.jiangjiang.eshop.membership.dto.UserDetailShowDTO;
import com.jiangjiang.eshop.membership.service.UserDetailService;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jws.Oneway;
import java.util.Objects;

/**
 * @ClassName UserDetailBiz
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/21 12:49
 * @Version 1.0
 **/
@Component
public class UserDetailBiz {
    @Autowired
    private UserAccountBiz userAccountBiz;
    @Autowired
    private UserDetailService userDetailService;
    @Autowired
    private UserDetailConvert userDetailConvert;

    /**
     * 显示用户详细信息
     *
     * @param userAccountId 用户账号id
     * @return 查询结果
     */
    public UserDetailShowDTO showDetail(Long userAccountId) {
        UserAccountDTO userAccountDTO = userAccountBiz.queryById(userAccountId);
        UserDetailEntity userDetail = userDetailService.queryDetailByUserAccountId(userAccountId);
        UserDetailDTO detailDTO = userDetailConvert.convertEntity2DTO(userDetail);
        if (Objects.isNull(detailDTO)) {
            detailDTO = new UserDetailDTO();
        }
        return UserDetailShowDTO.builder()
                .userAccountDTO(userAccountDTO)
                .userDetailDTO(detailDTO)
                .build();

    }

    /**
     * 更新用户详细信息
     * @param detailDTO 用户数据
     * @return 处理结果
     */
    public Boolean updateDetail(UserDetailDTO detailDTO) {
        // 参数校验
        detailDTO.paramCheck();

        UserDetailEntity entity = userDetailConvert.convertDTO2Entity(detailDTO);
        return userDetailService.updateById(entity);
    }
}
